package zb.controller;

import io.modelcontextprotocol.client.McpSyncClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/amap")
public class GaoDeChatController {


    private final List<McpSyncClient> mcpSyncClients;
    private final ChatClient chatClient;

    public GaoDeChatController(List<McpSyncClient> mcpSyncClients, ChatClient.Builder chatClient) {
        this.mcpSyncClients = mcpSyncClients;
        this.chatClient = chatClient.build();
    }

    @RequestMapping("/chat")
    public String chat(@RequestParam(required = false,name = "question") String question) {
        return chatClient.prompt("你是一位善于规划行程的AI智能助手，请根据用户的需求为用户规划合理的行程安排")
                .user(question)
                .toolCallbacks(SyncMcpToolCallbackProvider.syncToolCallbacks(mcpSyncClients))
                .call()
                .content();
    }

}
